package me.alex.databindingdemo;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.Observable;

import me.alex.databindingdemo.databinding.ActivityMainBinding;

public class MainActivity extends BaseDataBindActivity<ActivityMainBinding> {
    UserData user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        user = new UserData();
        user.setName("测试姓名");
        user.setAge("13");
        bind.setUser(user);
        bind.setChange(new Change());
        user.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
            @Override
            public void onPropertyChanged(Observable sender, int propertyId) {
                Log.e("onPropertyChanged", "Observable:" + sender + ",propertyId:" + propertyId);
            }
        });
    }

    @Override
    public int setLayout() {
        return R.layout.activity_main;
    }

    public class Change {
        public void addAge(View view) {
//            int a = Integer.parseInt(user.getAge());
//            a++;
            user.setAge(String.valueOf(Integer.parseInt(user.getAge())+1));
        }
    }
}